﻿using System.Collections.ObjectModel;
using Catel.Articles._03___MVVM.Models;
using Catel.Data;
using Catel.MVVM;

namespace Catel.Articles._03___MVVM.Examples.UserControlWithParameter
{
    /// <summary>
    /// Company view model.
    /// </summary>
    public class CompanyViewModel : ViewModelBase
    {
        #region Constructor & destructor
        /// <summary>
        /// Initializes a new instance of the <see cref="CompanyViewModel"/> class.
        /// </summary>
        /// <param name="company">The company.</param>
        public CompanyViewModel(Models.Company company)
            : base()
        {
            // Store values
            Company = company;
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets the title of the view model.
        /// </summary>
        /// <value>The title.</value>
        public override string Title { get { return "Company"; } }

        #region Models
        /// <summary>
        /// Gets or sets the company.
        /// </summary>
        [Model]
        public Models.Company Company
        {
            get { return GetValue<Models.Company>(CompanyProperty); }
            private set { SetValue(CompanyProperty, value); }
        }

        /// <summary>
        /// Register the Company property so it is known in the class.
        /// </summary>
        public static readonly PropertyData CompanyProperty = RegisterProperty("Company", typeof(Models.Company));

        /// <summary>
        /// Gets or sets the CEO.
        /// </summary>
        [ViewModelToModel("Company")]
        [Model]
        public Person CEO
        {
            get { return GetValue<Person>(CEOProperty); }
            private set { SetValue(CEOProperty, value); }
        }

        /// <summary>
        /// Register the CEO property so it is known in the class.
        /// </summary>
        public static readonly PropertyData CEOProperty = RegisterProperty("CEO", typeof(Person));
        #endregion

        #region View model
        /// <summary>
        /// Gets or sets the company name.
        /// </summary>
        [ViewModelToModel("Company")]
        public string Name
        {
            get { return GetValue<string>(NameProperty); }
            set { SetValue(NameProperty, value); }
        }

        /// <summary>
        /// Register the Name property so it is known in the class.
        /// </summary>
        public static readonly PropertyData NameProperty = RegisterProperty("Name", typeof(string));

        /// <summary>
        /// Gets or sets the CEO full name.
        /// </summary>
        [ViewModelToModel("CEO", "FullName")]
        public string CEOFullName
        {
            get { return GetValue<string>(CEOFullNameProperty); }
            set { SetValue(CEOFullNameProperty, value); }
        }

        /// <summary>
        /// Register the CEOFullName property so it is known in the class.
        /// </summary>
        public static readonly PropertyData CEOFullNameProperty = RegisterProperty("CEOFullName", typeof(string));

        /// <summary>
        /// Gets or sets the managers.
        /// </summary>
        [ViewModelToModel("CEO", "PersonCollection")]
        public ObservableCollection<Person> Managers
        {
            get { return GetValue<ObservableCollection<Person>>(ManagersProperty); }
            set { SetValue(ManagersProperty, value); }
        }

        /// <summary>
        /// Register the Managers property so it is known in the class.
        /// </summary>
        public static readonly PropertyData ManagersProperty = RegisterProperty("Managers", typeof(ObservableCollection<Person>));
        #endregion
        #endregion

        #region Methods
        #endregion
    }
}
